<?php

App::uses('AppModel', 'Model');

/**
 * Block Model
 * 
 * PHP versions 5
 * CAKEPHP versions 2.x
 * 
 * Green CMS - Content Management System and Framework Powerfull by Cakephp
 * Copyright 2012, GREEN GLOBAL CO., LTD (toancauxanh.vn)
 * 
 * CakePHP(tm) :  Rapid Development Framework (http://www.cakephp.org)
 * Copyright 2005-2011, Cake Software Foundation, Inc. (http://www.cakefoundation.org)
 *
 * Licensed under The MIT License
 * Redistributions of files must retain the above copyright notice.
 *
 * @author        Technology Lab No.I <tech1@toancauxanh.vn>
 * @link          
 * @package       Block.Model
 * @since         Green v 1.0
 * @license       MIT License (http://www.opensource.org/licenses/mit-license.php)
 *
 * @property BlockRegion $Region
 * @property BlockRole $Role
 */
class Block extends AppModel {

    /**
     * Display field
     *
     * @var string
     */
    public $displayField = 'title';

    /**
     * Name of the validation string domain to use when translating validation errors.
     *
     * @var string
     */
    public $validationDomain = 'system';

    /**
     * List of behaviors
     *
     * @var array
     */
    public $actsAs = array(
        'Translator',
        'Serializable'
    );

    /**
     * Defined fields using for I18n
     * 
     * @var array
     */
    public $translateFields = array('title', 'content');

    /**
     * Defined fields using serialize and unserialized
     * 
     * @var array
     */
    public $serializeFields = array('language', 'params');

    /**
     * Defined to load the config file stored.
     *
     * @var string
     */
    public $configKey = 'Block';

    /**
     * Timestamp Unix maps.
     *
     * @var array
     */
    public $timestamp = array(
        'created' => 'datetime',
        'updated' => 'datetime'
    );

    /**
     * Validation rules.
     *
     * @var array
     */
    public $validate = array(
        'description' => array(
            'required' => array(
                'rule' => '//',
                'on' => 'create',
                'required' => true,
                'message' => 'This field is not blank!',
            ),
            'notempty' => array(
                'allowEmpty' => false,
                'rule' => 'notempty',
                'message' => 'This is a required information',
            )
        ),
        'module' => array(
            'required' => array(
                'rule' => '//',
                'on' => 'create',
                'required' => true,
                'message' => 'This field is not blank!',
            ),
            'notempty' => array(
                'allowEmpty' => false,
                'rule' => 'notempty',
                'message' => 'This is a required information',
            )
        ),
        'delta' => array(
            'required' => array(
                'rule' => '//',
                'on' => 'create',
                'required' => true,
                'message' => 'This field is not blank!',
            ),
            'notempty' => array(
                'allowEmpty' => false,
                'rule' => 'notempty',
                'message' => 'This is a required information',
            )
        ),
        'custom' => array(
            'boolean' => array(
                'allowEmpty' => true,
                'rule' => 'boolean',
                'message' => 'Incorrect value for this field'
            )
        )
    );

    //The Associations below have been created with all possible keys, those that are not needed can be removed

    /**
     * hasMany associations.
     *
     * @var array
     */
    public $hasMany = array(
        'Region' => array(
            'className' => 'Block.BlockRegion',
            'foreignKey' => 'block_id',
            'dependent' => true
        )
    );

    /**
     * Binds to block nodes through role settings
     *
     * @var array
     */
    var $hasAndBelongsToMany = array(
        'Role' => array(
            'className' => 'User.Role',
            'with' => 'Block.BlockRole',
            'unique' => 'keepExisting',
        )
    );

}

?>